package com.derbysoft.ota.application.translator.rs;

import com.derbysoft.modules.eip.translator.Translator;
import com.derbysoft.ota.interfaces.protocol._2009a.WarningType;
import com.derbysoft.ota.interfaces.protocol._2009a.WarningsType;
import com.derbysoft.remote.dswitch.core.WarningDTO;
import com.derbysoft.remote.dswitch.core.WarningsDTO;
import com.googlecode.functionalcollections.FunctionalIterables;
import com.googlecode.functionalcollections.Injector;

public class WarningsTranslator implements Translator<WarningsDTO, WarningsType> {

	@Override
	public WarningsType translate(WarningsDTO source) {
		return FunctionalIterables.make(source.getWarningList()).inject(
			new WarningsType(), 
			new Injector<WarningsType, WarningDTO>() {
				public WarningsType apply(WarningsType memo, WarningDTO input) {
					memo.getWarning().add(each(input));
					return memo;
				}
			}
		);
	}
	
	private WarningType each(WarningDTO input) {
		WarningType warningType = new WarningType();
		warningType.setValue(input.getMessage());
		return warningType;
	}

}
